<template>
  <div class="app-container">
    <!-- 对话框(添加 / 修改) -->
    <el-dialog :title="dialogTitle" :visible.sync="dialogVisible" width="45%" v-dialogDrag append-to-body>
      <el-form ref="formRef" :model="formData" :rules="formRules" v-loading="formLoading" label-width="130px">
        <el-form-item label="关联业务订单编号" prop="orderNo">
          <el-input v-model="formData.orderNo" placeholder="请输入关联业务订单编号"/>
        </el-form-item>
      <el-form-item label="下单金价" prop="goldPrice">
          <el-input v-model="formData.goldPrice" placeholder="请输入下单金价"/>
        </el-form-item>
        <el-form-item label="黄金检测费" prop="checkFee">
          <el-input v-model="formData.checkFee" placeholder="请输入黄金检测费"/>
        </el-form-item>
        <el-form-item label="违约金额" prop="defaultFee">
          <el-input v-model="formData.defaultFee" placeholder="请输入违约金额"/>
        </el-form-item>
        <el-form-item label="物流费" prop="expressFee">
          <el-input v-model="formData.expressFee" placeholder="请输入物流费"/>
        </el-form-item>
        <el-form-item label="黄金服务费" prop="serviceFee">
          <el-input v-model="formData.serviceFee" placeholder="请输入黄金服务费"/>
        </el-form-item>
        <el-form-item label="计价克重" prop="realGoldWeight">
          <el-input v-model="formData.realGoldWeight" placeholder="请输入计价克重"/>
        </el-form-item>

        <el-form-item label="估价金额" prop="expectAmount">
          <el-input v-model="formData.expectAmount" placeholder="请输入估价金额"/>
        </el-form-item>
        <el-form-item label="结算金额" prop="settlementAmount">
          <el-input v-model="formData.settlementAmount" placeholder="请输入结算金额"/>
        </el-form-item>
        <el-form-item label="订单状态" prop="status">
          <el-select v-model="formData.status" placeholder="请选择状态">
            <el-option v-for="dict in this.getDictDatas(DICT_TYPE.EXPECT_PRICE_STATUS)"
                       :key="dict.value" :label="dict.label" :value="parseInt(dict.value)"/>
          </el-select>
        </el-form-item>
        <el-form-item label="争议状态" prop="controversyStatus">
          <el-select v-model="formData.controversyStatus" placeholder="请选择状态">
            <el-option v-for="dict in this.getDictDatas(DICT_TYPE.CONTROVERSY_STATUS)"
                       :key="dict.value" :label="dict.label" :value="parseInt(dict.value)"/>
          </el-select>
        </el-form-item>
        <el-form-item label="最终确认时间" prop="confirmTime">
          <el-date-picker clearable v-model="formData.confirmTime" type="date" value-format="timestamp"
                          placeholder="选择最终确认时间"/>
        </el-form-item>
        <el-form-item label="争议备注" prop="remark">
          <el-input v-model="formData.remark" placeholder="请输入描述"/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
<!--        <el-button type="primary" @click="submitForm" :disabled="formLoading">确 定</el-button>-->
        <el-button @click="dialogVisible = false">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import * as OrderExpectPriceInfoApi from '@/api/system/orderexpectpriceinfo';

export default {
  name: "OrderExpectPriceInfoForm",
  components: {},
  data() {
    return {
      // 弹出层标题
      dialogTitle: "",
      // 是否显示弹出层
      dialogVisible: false,
      // 表单的加载中：1）修改时的数据加载；2）提交的按钮禁用
      formLoading: false,
      // 表单参数
      formData: {
        id: undefined,
        goldPrice: undefined,
        orderNo: undefined,
        expectAmount: undefined,
        settlementAmount: undefined,
        status: undefined,
        confirmTime: undefined,
        remark: undefined,
        serviceFee: null,
        realGoldWeight: null,
        expressFee: null,
        defaultFee: null,
        checkFee: null
      },
      // 表单校验
      formRules: {},
    };
  },
  methods: {
    /** 打开弹窗 */
    async open(id) {
      this.dialogVisible = true;
      this.reset();
      // 修改时，设置数据
      if (id) {
        this.formLoading = true;
        try {
          const res = await OrderExpectPriceInfoApi.getOrderExpectPriceInfo(id);
          this.formData = res.data;
          this.title = "修改订单估价信息";
        } finally {
          this.formLoading = false;
        }
      }
      this.title = "新增订单估价信息";
    },
    /** 提交按钮 */
    async submitForm() {
      // 校验主表
      await this.$refs["formRef"].validate();
      this.formLoading = true;
      try {
        const data = this.formData;
        // 修改的提交
        if (data.id) {
          await OrderExpectPriceInfoApi.updateOrderExpectPriceInfo(data);
          this.$modal.msgSuccess("修改成功");
          this.dialogVisible = false;
          this.$emit('success');
          return;
        }
        // 添加的提交
        await OrderExpectPriceInfoApi.createOrderExpectPriceInfo(data);
        this.$modal.msgSuccess("新增成功");
        this.dialogVisible = false;
        this.$emit('success');
      } finally {
        this.formLoading = false;
      }
    },
    /** 表单重置 */
    reset() {
      this.formData = {
        id: undefined,
        orderNo: undefined,
        expectAmount: undefined,
        settlementAmount: undefined,
        status: undefined,
        confirmTime: undefined,
        remark: undefined,
      };
      this.resetForm("formRef");
    }
  }
};
</script>
